#!/usr/bin/python3
import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

from selenium.webdriver.support.select import Select
from PIL import Image
import os
from selenium.webdriver.chrome.options import Options


#URL="https://forms.gle/mrPxTaxoPW6PiQUG9"
URL="https://docs.google.com/forms/d/e/1FAIpQLSdXzWHUfR9k3MT93w2o87hUUCUgt3pIRLupbDc4iEZz-sGZTw/viewform"
 
def Start_Fill(last_name, first_name, dob, gender, email_id, phone, address, city, state, zip_code, passport):

    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--user-agent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"')
    chrome_options.add_argument('--disable-blink-features=AutomationControlled') 
    chrome_options.add_argument("window-size=1280,800")
    driver = webdriver.Chrome(options=chrome_options)
    driver.implicitly_wait(15)
    driver.get(URL)

    email_e = driver.find_element_by_xpath("//div/input[@type='email']")
    ActionChains(driver).move_to_element(email_e).perform()
    email_e.click()
    email_e.send_keys(email_id)
    time.sleep(1)
    #golden sail
    first_name_e = driver.find_element_by_id("i9")
    ActionChains(driver).move_to_element(first_name_e).perform()
    first_name_e.click()
    time.sleep(0.1)

    #passport
    id_e = driver.find_element_by_xpath("//div/input[@aria-labelledby='i12']")
    ActionChains(driver).move_to_element(id_e).perform()
    id_e.click()
    id_e.send_keys(passport)
    time.sleep(0.1)

    #first_name
    first_name_e = driver.find_element_by_xpath("//div/input[@aria-labelledby='i16']")
    ActionChains(driver).move_to_element(first_name_e).perform()
    first_name_e.click()
    first_name_e.send_keys(first_name)
    time.sleep(1)

    #last_name
    last_name_e = driver.find_element_by_xpath("//div/input[@aria-labelledby='i20']")
    ActionChains(driver).move_to_element(last_name_e).perform()
    last_name_e.click()
    last_name_e.send_keys(last_name)
    time.sleep(0.2)

    #dob
    dob_e = driver.find_element_by_xpath("//div/input[@type='date']")
    ActionChains(driver).move_to_element(dob_e).perform()
    dob_e.send_keys(dob)
    time.sleep(0.14)

    #gender
    if gender == "M":
    #gender-male
        gender_e = driver.find_element_by_id("i33")
        ActionChains(driver).move_to_element(gender_e).perform()
        gender_e.click()

    elif gender == "F":
        #gender-female
        gender_e = driver.find_element_by_id("i36")
        ActionChains(driver).move_to_element(gender_e).perform()
        gender_e.click()
    time.sleep(0.80)

    #race
    race_e = driver.find_element_by_id("i52")
    ActionChains(driver).move_to_element(race_e).perform()
    race_e.click()   
    time.sleep(0.73)

    #ethnicity
    Ethnicity  = driver.find_element_by_id("i77")
    ActionChains(driver).move_to_element(Ethnicity).perform()
    Ethnicity.click()
    time.sleep(0.90)

    #address
    address_e = driver.find_element_by_xpath("//div/input[@aria-labelledby='i83']")
    ActionChains(driver).move_to_element(address_e).perform()
    address_e.click()
    address_e.send_keys(address)
    time.sleep(0.33)

    #city
    city_e = driver.find_element_by_xpath("//div/input[@aria-labelledby='i87']")
    ActionChains(driver).move_to_element(city_e).perform()
    city_e.click()
    city_e.send_keys(city)
    time.sleep(0.57)

    #county
    state_e = driver.find_element_by_id('i95')
    ActionChains(driver).move_to_element(state_e).perform()
    state_e.click()
    #state_e.send_keys(state)
    time.sleep(0.91)
    
    #state
    state_e = driver.find_element_by_id('i114')
    ActionChains(driver).move_to_element(state_e).perform()
    state_e.click()
    #state_e.send_keys(state)
    time.sleep(0.81)

    #zip_code
    zip_code_e = driver.find_element_by_xpath("//div/input[@aria-labelledby='i120']")
    ActionChains(driver).move_to_element(zip_code_e).perform()
    zip_code_e.click()
    zip_code_e.send_keys(zip_code)
    time.sleep(0.84)

    #experience
    county = driver.find_element_by_id("i129")
    ActionChains(driver).move_to_element(county).perform()
    county.click()

    #phone
    phone_e = driver.find_element_by_xpath("//div/input[@aria-labelledby='i165']")
    ActionChains(driver).move_to_element(phone_e).perform()
    phone_e.click()
    phone_e.send_keys(phone)

    time.sleep(0.68)
    acid_e = driver.find_element_by_id("i173")
    ActionChains(driver).move_to_element(acid_e).perform()
    acid_e.click()
    
    #time.sleep(0.87)
    #anti_e = driver.find_element_by_id("i114")
    #ActionChains(driver).move_to_element(anti_e).perform()
    #anti_e.click()
    
    time.sleep(1.21)
    onsite_e = driver.find_element_by_id("i189")
    ActionChains(driver).move_to_element(onsite_e).perform()
    onsite_e.click()
         
    time.sleep(320)
    driver.quit()

#sudo apt install tesseract-ocr
#sudo apt install libtesseract-dev
#sudo apt install python3-opencv
#sudo apt install python3-opencv
#sudo apt install python3-pil
#pip3 install pysseract

if __name__ == "__main__":
    data_dict = {
   'last_name': "Xie",
   'first_name': "Changcai",
   'dob': "1983/08/19",
   'gender':'F',
   'email_id': 'xiechc@gmail.com',
   'phone': '18910158363',
   'address': '35 Lane Apt 23',
   'city': "Walnut Creek",
   'state': 'CA',
   'zip_code': '100086',
   'passport': "4444",
    }
    Start_Fill(**data_dict)


